package com.jdrx.sw.sewage.api.web;

import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.AlarmQueryDTO;
import com.jdrx.sw.sewage.beans.dto.CloseAlarmDTO;
import com.jdrx.sw.sewage.beans.dto.HandleIdeaDTO;
import com.jdrx.sw.sewage.beans.vo.AlarmNumVO;
import com.jdrx.sw.sewage.beans.vo.AlarmVO;
import com.jdrx.sw.sewage.beans.vo.base.PageVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.AlarmHandleServiceImpl;
import com.jdrx.sw.sewage.service.AlarmServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/alarm")
@Api(value = "告警模块")
public class AlarmApi {

    public static final Logger logger = LoggerFactory.getLogger(AlarmApi.class);

    @Autowired
    private AlarmHandleServiceImpl alarmHandleServiceImpl;
    @Autowired
    private AlarmServiceImpl alarmServiceImpl;
    /*@Autowired
    private GatherDevPoiServiceImpl gatherDevPoiServiceImpl;

    @ApiOperation(value = "查询当前登陆人责任得站点的厂区")
    @RequestMapping(value = "selectFactoryPeriodList", method = RequestMethod.POST)
    public ResponseVO<List<Integer>> selectFactoryPeriodList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                             @RequestBody List<Long> dutyUserStationIds) {
        return ResponseFactory2.ok(gatherDevPoiServiceImpl.selectFactoryPeriodList(dutyUserStationIds));
    }*/

    @ApiOperation(value = "未读告警数 & 处理中告警数 &已完成告警数 & 未读和处理中告警数")
    @RequestMapping(value = "selectAllAlarmNum", method = RequestMethod.POST)
    public ResponseVO<AlarmNumVO> selectAllAlarmNum(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                    @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                    @RequestBody List<Long> stationIds) throws BizException {
        return ResponseFactory2.ok(alarmServiceImpl.selectAllAlarmNum(stationIds, null));
    }

    @ApiOperation(value = "告警分页查询")
    @RequestMapping(value = "selectAlarmByPage", method = RequestMethod.POST)
    public ResponseVO<PageVO<AlarmVO>> selectByPage(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                    @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                    @RequestBody AlarmQueryDTO alarmQueryDTO) {
        return ResponseFactory2.ok(alarmServiceImpl.selectAlarmByPage(alarmQueryDTO));
    }

    @ApiOperation(value = "告警详情查询")
    @RequestMapping(value = "selectAlarmDetail", method = RequestMethod.GET)
    public ResponseVO selectAlarmDetail(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                        @RequestHeader(Constant.TENANT_ID) String tenantId,
                                        @RequestParam String dutyUserName,
                                        @RequestParam Long alarmId) {
        return ResponseFactory2.ok(alarmServiceImpl.selectAlarmDetail(alarmId, dutyUserName));
    }

    @ApiOperation(value = "关闭告警")
    @RequestMapping(value = "closeAlarm", method = RequestMethod.POST)
    public ResponseVO closeAlarm(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                 @RequestHeader(Constant.TENANT_ID) String tenantId,
                                 @RequestBody CloseAlarmDTO closeAlarmDTO) throws BizException {
        return alarmServiceImpl.closeAlarm(closeAlarmDTO, dataNode);
    }

    @ApiOperation(value = "处理意见")
    @RequestMapping(value = "handleIdea", method = RequestMethod.POST)
    public ResponseVO handleIdea(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                 @RequestHeader(Constant.TENANT_ID) String tenantId,
                                 @RequestBody HandleIdeaDTO handleIdeaDTO) {
        return alarmHandleServiceImpl.handleIdea(handleIdeaDTO, null);
    }
}
